﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GISSystem.Class;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;

namespace GISSystem.WindowsForm
{
    public partial class frm_Overview : Form
    {
        MapOperator op;
        public MapOperator overviewOp;
        IEnvelope pEnvelope;
        MainFormUI ui;

        public frm_Overview(MapOperator map, MainFormUI ui)
        {
            InitializeComponent();

            this.ui = ui;
            op = map;
            overviewOp = new MapOperator(mapOverview);
        }

        private void frm_Overview_Shown(object sender, EventArgs e)
        {
            //显示与主界面相同的地图，并使之总是显示全图
            overviewOp.LoadMxd(Configuration.MxdPath);
            overviewOp.FullExtent();

            this.SetStyle(ControlStyles.EnableNotifyMessage, true);
        }

        private void mapOverview_OnAfterDraw(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterDrawEvent e)
        {
            IEnvelope pEnv = op.ActiveView.Extent;

            if (pEnv == null)
            {
                return;
            }

            esriViewDrawPhase phase = (esriViewDrawPhase)e.viewDrawPhase;

            if (phase == esriViewDrawPhase.esriViewForeground)
            {

                IRgbColor color = new RgbColorClass();
                color.RGB = 255;

                ILineSymbol outline = new SimpleLineSymbolClass();
                outline.Color = color;
                outline.Width = 1.5;

                ISimpleFillSymbol pSFS = new SimpleFillSymbolClass();
                pSFS.Outline = outline;
                pSFS.Style = esriSimpleFillStyle.esriSFSHollow;

                object obj = pSFS;

                mapOverview.DrawShape(pEnv as IGeometry, ref obj);
            }
        }

        private void frm_Overview_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;

            ui.HideOverview();
        }


    }
}